package com.wanmait.travel.util;

import java.util.ArrayList;
import java.util.List;

import com.wanmait.travel.vo.ScenicTickitType;
import com.wanmait.travel.vo.Tickit;

public class ShopCar {
	private List<ScenicTickitType> stts =new ArrayList<ScenicTickitType>();
	
	public void clear() {
		stts.clear();
	}
	
	
	public void addCount(Integer scenicId,Integer tickitChildCount,Integer tickitManCount,Integer tickitOldCount) {
		for(int i=0;stts!=null&&i<stts.size();i++) {
			if(stts.get(i).getScenic().getId().equals(scenicId)) {
				
				if(tickitChildCount!=null) {
				stts.get(i).getTickitChild().setTickitCount(stts.get(i).getTickitChild().getTickitCount()+tickitChildCount);
				if(stts.get(i).getTickitChild().getTickitCount()<0) {
					stts.get(i).getTickitChild().setTickitCount(0);
				}
				}
				
				
				if(tickitManCount!=null) {
				stts.get(i).getTickitMan().setTickitCount(stts.get(i).getTickitMan().getTickitCount()+tickitManCount);
				if(stts.get(i).getTickitMan().getTickitCount()<0) {
					stts.get(i).getTickitMan().setTickitCount(0);
				}
				}
				
				
				if(tickitOldCount!=null) {
				stts.get(i).getTickitOld().setTickitCount(stts.get(i).getTickitOld().getTickitCount()+tickitOldCount);
				if(stts.get(i).getTickitOld().getTickitCount()<0) {
					stts.get(i).getTickitOld().setTickitCount(0);
				}
				}
				
				break;
			}
	}
	}
	
	
	public Double getTotalPrice() {
			double total=0.0;
			double child=0.0;
			double old=0.0;
			double man=0.0;
			for(ScenicTickitType stt:stts) {
				if(stt.getTickitChild()!=null) {
				child=stt.getTickitChild().getPrice()*stt.getTickitChild().getTickitCount();
				}
				if(stt.getTickitMan()!=null) {
				man=stt.getTickitMan().getPrice()*stt.getTickitMan().getTickitCount();
				}
				if(stt.getTickitOld()!=null) {
				old=stt.getTickitOld().getPrice()*stt.getTickitOld().getTickitCount();
				}
				total=child+man+old;
			}
		return total;
	}
	
	
	public void addScenicTickitType(ScenicTickitType stt,String tcv,String tov,String tmv) {
		boolean find =false;
		String kong="undefined";
		for(ScenicTickitType addStt:stts) {
			if(addStt.getScenic().getId().equals(stt.getScenic().getId())) {
				find=true;
				if(!tcv.equals(kong)) {
					int tcV=Integer.parseInt(tcv);
					stt.getTickitChild().setTickitCount(stt.getTickitChild().getTickitCount()+tcV);
				}
				if(!tov.equals(kong)) {
					int toV=Integer.parseInt(tov);
					stt.getTickitOld().setTickitCount(stt.getTickitOld().getTickitCount()+toV);
				}
				if(!tmv.equals(kong)) {
					int tmV=Integer.parseInt(tmv);
					stt.getTickitMan().setTickitCount(stt.getTickitMan().getTickitCount()+tmV);
				}
				break;
			}
		}
		if(!find) {
			
			if(!tcv.equals(kong)) {
				int tcV=Integer.parseInt(tcv);
				stt.getTickitChild().setTickitCount(stt.getTickitChild().getTickitCount()+tcV);
			}
			if(!tov.equals(kong)) {
				int toV=Integer.parseInt(tov);
				stt.getTickitOld().setTickitCount(stt.getTickitOld().getTickitCount()+toV);
			}
			if(!tmv.equals(kong)) {
				int tmV=Integer.parseInt(tmv);
				stt.getTickitMan().setTickitCount(stt.getTickitMan().getTickitCount()+tmV);
			}
			stts.add(stt);
		}
	}
	
	public List<ScenicTickitType> getScenics() {
		return stts;
	}
	
	
	
}
